/**
 * ComponentTypeListCellRenderer.java
 * 2012-3-20 下午10:45:13
 */
package xgenerator.ui.swing;

import java.awt.Component;
import java.io.Serializable;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import xgenerator.constants.ComponentTypes;

/**
 * <p>
 * Title:类的中文名
 * </p>
 * <p>
 * Description:具体功能见各方法描述
 * </p>
 * <p>
 * Copyright:Copyright (c) 2012
 * </p>
 * 
 * @author <a href="mailto:lishushan@gmail.com">liss</a>
 * @version 1.0
 */
public class ComponentTypeListCellRenderer extends JLabel implements ComponentTypes, UIConstants, ListCellRenderer, Serializable {

	public ComponentTypeListCellRenderer() {
		setOpaque(true);
	}
	
	/**
	 * <p>
	 * Title：功能方法名
	 * </p>
	 * @param list
	 * @param value
	 * @param index
	 * @param isSelected
	 * @param cellHasFocus
	 * @return
	 * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
	 */
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		if(null != value) {
			this.setText(value.toString());
			if(TEXT_FIELD.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "textfield.png"));
			} else if(DATE_FIELD.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "date.png"));
			} else if(NUMBER_FIELD.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "textfield.png"));
			} else if(TEXT_AREA.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "comment.png"));
			} else if(RICH_TEXT_EDITOR.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "style.png"));
			} else if(CHECKBOX.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "unchecked.gif"));
			} else if(RADIO_BUTTON.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "radio.jpg"));
			} else if(FILE_FIELD.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "attach.png"));
			} else if(HIDDEN.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "key.png"));
			} else if(IMAGE_FIELD.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "image.png"));
			} else if(PASSWORD_FIELD.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "textfield_key.png"));
			} else if(BUTTON.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "plugin.png"));
			} else if(RESET_BUTTON.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "plugin.png"));
			} else if(SUBMIT_BUTTON.equals(value)) {
				this.setIcon(IconUtils.createImageIcon(ICON_CLASS_PATH + "plugin.png"));
			}
		}
		if(isSelected) {
			this.setBackground(list.getSelectionBackground());
			this.setForeground(list.getSelectionForeground());
		} else {
			this.setBackground(list.getBackground());
			this.setForeground(list.getForeground());
		}
		return this;
	}

}
